//****************************************************************
// Autor:   Yimy Juarez 
//       
// Seccion: 10
// Nombre del Archivo: UsoCalculadora.java
// Fecha de Modificacion: 14/08/2012
// Descripcion:
// Modelado de interfaz grafica de la calculadora
// ***************************************************************
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hojadetrabajo4;


/**
 *
 * @author Roberto
 */
public class UsoCalculadora extends javax.swing.JFrame {

    /**
     * Creates new form UsoStack
     */
    
    Stack<Integer> operando;
    List<Integer> operando1;
    StackFactory<Integer> seleccionPila=new StackFactory<Integer>();
    ListaFactory<Integer> seleccionLista=new ListaFactory<Integer>();
    
    int num1, num2;
    int resultado;
    String   temp;
    boolean decision=false;
    public UsoCalculadora() {
        initComponents();
        
    }
private void Habilitar(){
        m1.setEnabled(true);
        m2.setEnabled(true);
        m3.setEnabled(true);
        m4.setEnabled(true);
        m5.setEnabled(true);
        m6.setEnabled(true);
        m7.setEnabled(true);
        m8.setEnabled(true);
        m9.setEnabled(true);
        m15.setEnabled(true);
        m16.setEnabled(true);
        m14.setEnabled(true);
        sum.setEnabled(true);
        mult.setEnabled(true);
        div.setEnabled(true);
        sus.setEnabled(true);
        
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        panel2 = new javax.swing.JPanel();
        m1 = new javax.swing.JButton();
        m2 = new javax.swing.JButton();
        m3 = new javax.swing.JButton();
        m4 = new javax.swing.JButton();
        m5 = new javax.swing.JButton();
        m6 = new javax.swing.JButton();
        m7 = new javax.swing.JButton();
        m8 = new javax.swing.JButton();
        m9 = new javax.swing.JButton();
        sum = new javax.swing.JButton();
        mult = new javax.swing.JButton();
        div = new javax.swing.JButton();
        sus = new javax.swing.JButton();
        m14 = new javax.swing.JButton();
        m15 = new javax.swing.JButton();
        m16 = new javax.swing.JButton();
        result = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        listas = new javax.swing.JComboBox();
        pilas = new javax.swing.JComboBox();

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(51, 51, 255));

        jLabel1.setToolTipText("");
        jLabel1.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jLabel1AncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        panel2.setBackground(new java.awt.Color(0, 0, 255));

        m1.setText("1");
        m1.setEnabled(false);
        m1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m1ActionPerformed(evt);
            }
        });

        m2.setText("2");
        m2.setEnabled(false);
        m2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m2ActionPerformed(evt);
            }
        });

        m3.setText("3");
        m3.setEnabled(false);
        m3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m3ActionPerformed(evt);
            }
        });

        m4.setText("4");
        m4.setEnabled(false);
        m4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m4ActionPerformed(evt);
            }
        });

        m5.setText("5");
        m5.setEnabled(false);
        m5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m5ActionPerformed(evt);
            }
        });

        m6.setText("6");
        m6.setEnabled(false);
        m6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m6ActionPerformed(evt);
            }
        });

        m7.setText("7");
        m7.setEnabled(false);
        m7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m7ActionPerformed(evt);
            }
        });

        m8.setText("8");
        m8.setEnabled(false);
        m8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m8ActionPerformed(evt);
            }
        });

        m9.setText("9");
        m9.setEnabled(false);
        m9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m9ActionPerformed(evt);
            }
        });

        sum.setText("+");
        sum.setEnabled(false);
        sum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sumActionPerformed(evt);
            }
        });

        mult.setText("*");
        mult.setEnabled(false);
        mult.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multActionPerformed(evt);
            }
        });

        div.setText("/");
        div.setEnabled(false);
        div.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                divActionPerformed(evt);
            }
        });

        sus.setText("-");
        sus.setEnabled(false);
        sus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                susActionPerformed(evt);
            }
        });

        m14.setText("=");
        m14.setEnabled(false);
        m14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m14ActionPerformed(evt);
            }
        });

        m15.setText("0");
        m15.setEnabled(false);
        m15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m15ActionPerformed(evt);
            }
        });

        m16.setText("C");
        m16.setEnabled(false);
        m16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m16ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
        panel2.setLayout(panel2Layout);
        panel2Layout.setHorizontalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addComponent(m4, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m5, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(m6, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(div, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addComponent(m7, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m8, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(m9, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(sum, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(panel2Layout.createSequentialGroup()
                                .addComponent(m1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(m2, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(m3, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(panel2Layout.createSequentialGroup()
                                .addComponent(m16, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(m15, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(m14, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(mult, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sus, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        panel2Layout.setVerticalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(m7)
                    .addComponent(m9)
                    .addComponent(m8)
                    .addComponent(sum))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(m4)
                    .addComponent(m6)
                    .addComponent(div)
                    .addComponent(m5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(m1)
                    .addComponent(m2)
                    .addComponent(m3)
                    .addComponent(mult))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(m14)
                    .addComponent(sus)
                    .addComponent(m15)
                    .addComponent(m16))
                .addContainerGap())
        );

        result.setBackground(new java.awt.Color(255, 255, 102));
        result.setEditable(false);
        result.setForeground(new java.awt.Color(51, 51, 255));
        result.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resultActionPerformed(evt);
            }
        });

        jButton3.setText("Usar Lista");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Usar Pila");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        listas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Circular", "Doble", "Simple" }));
        listas.setEnabled(false);
        listas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listasActionPerformed(evt);
            }
        });

        pilas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arreglo", "Vector", "Lista" }));
        pilas.setEnabled(false);
        pilas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pilasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(result, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(listas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(pilas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(result, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(listas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pilas))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel1AncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jLabel1AncestorAdded
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel1AncestorAdded

    private void m1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m1ActionPerformed
        if(decision){
            operando.push(1);
            result.setText(result.getText()+m1.getText());
            // TODO add your handling code here:
            }
        else
        {
            operando1.addLast(1);
            result.setText(result.getText()+m1.getText());
        }
    }//GEN-LAST:event_m1ActionPerformed

    private void m2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m2ActionPerformed
        if(decision){
            operando.push(2);
            result.setText(result.getText()+m2.getText());
            }
        else
        {
            operando1.addLast(2);
            result.setText(result.getText()+m2.getText());
        }
                // TODO add your handling code here:
    }//GEN-LAST:event_m2ActionPerformed

    private void m3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m3ActionPerformed
       if(decision){   
            operando.push(3);
            result.setText(result.getText()+m3.getText());
            }
       else{
           operando1.addLast(3);
           result.setText(result.getText()+m3.getText());
       }
             // TODO add your handling code here:
    }//GEN-LAST:event_m3ActionPerformed

    private void m4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m4ActionPerformed
        if(decision)
        {
            operando.push(4);
            result.setText(result.getText()+m4.getText());
        }
        else
        {
            operando1.addLast(4);
            result.setText(result.getText()+m4.getText());
        }
              // TODO add your handling code here:
    }//GEN-LAST:event_m4ActionPerformed

    private void m5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m5ActionPerformed
        if(decision)
        {
            operando.push(5);
            result.setText(result.getText()+m5.getText());
         }
        else
        {
            operando1.addLast(5);
            result.setText(result.getText()+m5.getText());
            
        }
            // TODO add your handling code here:
    }//GEN-LAST:event_m5ActionPerformed

    private void m6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m6ActionPerformed
        if(decision)
            {
            operando.push(6);
            result.setText(result.getText()+m6.getText());
            }
        else
        {
            operando1.addLast(6);
            result.setText(result.getText()+m6.getText());
        }
               // TODO add your handling code here:
    }//GEN-LAST:event_m6ActionPerformed

    private void m7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m7ActionPerformed
        if(decision)
        {
            operando.push(7);
            result.setText(result.getText()+m7.getText());
        }        // TODO add your handling code here:
        else
        {
            operando1.addLast(7);
            result.setText(result.getText()+m7.getText());
        }
    }//GEN-LAST:event_m7ActionPerformed

    private void m8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m8ActionPerformed
        if(decision)
        {
            operando.push(8);
            result.setText(result.getText()+m8.getText());
         }
        else
        {
            operando1.addLast(8);
            result.setText(result.getText()+m8.getText());
        }
            // TODO add your handling code here:
    }//GEN-LAST:event_m8ActionPerformed

    private void m9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m9ActionPerformed
        if(decision)    
        {
            operando.push(9);
            result.setText(result.getText()+m9.getText());
         }
        else
        {
            operando1.addLast(9);
            result.setText(result.getText()+m9.getText());
        }
            // TODO add your handling code here:
    }//GEN-LAST:event_m9ActionPerformed

    private void sumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sumActionPerformed
        if(decision)
        {
            result.setText(result.getText()+sum.getText());
            if(operando.empty())
            {

            } 
            else
            {
                if(operando.size()>1)           {
                    num1=Integer.parseInt(operando.pop().toString());
                    num2=Integer.parseInt(operando.pop().toString());
                    resultado=num1+num2;
                    operando.push(resultado);

                }      
            } 
        }
        else
        {
            result.setText(result.getText()+sum.getText());
            if(operando1.isEmpty())
            {

            } 
            else
            {
                if(operando1.size()>1)           {
                    num1=Integer.parseInt(operando1.removeLast().toString());
                    num2=Integer.parseInt(operando1.removeLast().toString());
                    resultado=num1+num2;
                    System.out.println("hola"+resultado);
                    operando1.addLast(resultado);
                    System.out.println(operando1.isEmpty());

                }      
            }
        }
    }//GEN-LAST:event_sumActionPerformed

    private void multActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multActionPerformed
        if(decision)
        {
            result.setText(result.getText()+mult.getText());
            if(operando.empty())
            {

            } 
            else
            {
                if(operando.size()>1)           {
                    num1=Integer.parseInt(operando.pop().toString());
                    num2=Integer.parseInt(operando.pop().toString());
                    resultado=num1*num2;
                    operando.push(resultado);

                }      
            } 
        }
        else
        {
            result.setText(result.getText()+mult.getText());
            if(operando1.isEmpty())
            {

            } 
            else
            {
                if(operando1.size()>1)           {
                    num1=Integer.parseInt(operando1.removeLast().toString());
                    num2=Integer.parseInt(operando1.removeLast().toString());
                    resultado=num1*num2;
                    operando1.addLast(resultado);

                }      
            }
        }
        
    }//GEN-LAST:event_multActionPerformed

    private void divActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_divActionPerformed
        if(decision)
        {
            result.setText(result.getText()+div.getText());
            if(operando.empty())
            {

            } 
            else
            {
                if(operando.size()>1)           {
                    num1=Integer.parseInt(operando.pop().toString());
                    num2=Integer.parseInt(operando.pop().toString());
                    resultado=num2/num1;
                    operando.push(resultado);

                }      
            } 
        }
        else
        {
            result.setText(result.getText()+div.getText());
            if(operando1.isEmpty())
            {

            } 
            else
            {
                if(operando1.size()>1)           {
                    num1=Integer.parseInt(operando1.removeLast().toString());
                    num2=Integer.parseInt(operando1.removeLast().toString());
                    resultado=num2/num1;
                    operando1.addLast(resultado);
                    

                }      
            }
        }
    }//GEN-LAST:event_divActionPerformed

    private void susActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_susActionPerformed
        if(decision)
        {
            result.setText(result.getText()+sus.getText());
            if(operando.empty())
            {

            } 
            else
            {
                if(operando.size()>1)           {
                    num1=Integer.parseInt(operando.pop().toString());
                    num2=Integer.parseInt(operando.pop().toString());
                    resultado=num2-num1;
                    operando.push(resultado);

                }      
            } 
        }
        else
        {
            result.setText(result.getText()+sus.getText());
            if(operando1.isEmpty())
            {

            } 
            else
            {
                if(operando1.size()>1)           {
                    num1=Integer.parseInt(operando1.removeLast().toString());
                    num2=Integer.parseInt(operando1.removeLast().toString());
                    resultado=num2-num1;
                    operando1.addLast(resultado);

                }      
            }
        } 
        // TODO add your handling code here:
    }//GEN-LAST:event_susActionPerformed

    private void m14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m14ActionPerformed
        if(decision)
        {
            if(operando.empty())
            { 
                result.setText(""); 
            } 
            else
            { 
                result.setText(operando.peek().toString());
             }
        }
         else
        {   System.out.println(operando1.isEmpty());
            if(operando1.isEmpty())
               {
                    result.setText(""); 
                    
            
               }
            else
               {
                   
                   num1=Integer.parseInt(operando1.removeLast().toString());
                   temp = Integer.toString(num1); 
                     result.setText(temp);
                    
                   

               }   
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_m14ActionPerformed

    private void m15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m15ActionPerformed
        if(decision)    
        {
            operando.push(0);
            result.setText(result.getText()+m15.getText());
         }
        else
        {
            operando1.addLast(0);
            result.setText(result.getText()+m15.getText());
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_m15ActionPerformed

    private void resultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resultActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_resultActionPerformed

    private void m16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m16ActionPerformed
        result.setText("");
        if(decision)
        {
            while(!operando.empty())
                {
                    operando.pop();
                }
        }
        else
        {
            while(!operando1.isEmpty())
                {
                    operando1.removeLast();
                }
        }
            
           // TODO add your handling code here:
    }//GEN-LAST:event_m16ActionPerformed

    private void listasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listasActionPerformed
         
        if (listas.getSelectedIndex()==0)
         {
             operando1=seleccionLista.getLista(1);
             System.out.println(operando1.isEmpty());
             listas.setEnabled(false);
                     
         }
         else if(listas.getSelectedIndex()==1)
         {
             operando1=seleccionLista.getLista(2);
             System.out.println(operando1.isEmpty());
             listas.setEnabled(false);
         }
         else
         {
             operando1=seleccionLista.getLista(3);
             System.out.println(operando1.isEmpty());
             listas.setEnabled(false);
         }
         System.out.println(decision);
         Habilitar();
          
        // TODO add your handling code here:
    }//GEN-LAST:event_listasActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        
        listas.setEnabled(true);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        
    }//GEN-LAST:event_jButton3ActionPerformed

    private void pilasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pilasActionPerformed
         if (pilas.getSelectedIndex()==0)
         {
             operando=seleccionPila.getStack(1);
             pilas.setEnabled(false);
                     
         }
         else if(listas.getSelectedIndex()==1)
         {
             operando=seleccionPila.getStack(2);
             pilas.setEnabled(false);
         }
         else
         {
             operando=seleccionPila.getStack(3);
             pilas.setEnabled(false);
         }
         Habilitar();
        
        // TODO add your handling code here:
    }//GEN-LAST:event_pilasActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        decision=true;
        pilas.setEnabled(true);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
                
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UsoCalculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UsoCalculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UsoCalculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UsoCalculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new UsoCalculadora().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton div;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox listas;
    private javax.swing.JButton m1;
    private javax.swing.JButton m14;
    private javax.swing.JButton m15;
    private javax.swing.JButton m16;
    private javax.swing.JButton m2;
    private javax.swing.JButton m3;
    private javax.swing.JButton m4;
    private javax.swing.JButton m5;
    private javax.swing.JButton m6;
    private javax.swing.JButton m7;
    private javax.swing.JButton m8;
    private javax.swing.JButton m9;
    private javax.swing.JButton mult;
    private javax.swing.JPanel panel2;
    private javax.swing.JComboBox pilas;
    private javax.swing.JTextField result;
    private javax.swing.JButton sum;
    private javax.swing.JButton sus;
    // End of variables declaration//GEN-END:variables
}
